package com.kgc.cgprovider.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kgc.basic.util.PageInfo;
import com.kgc.basic.util.ResponseMsg;
import com.kgc.cgapi.pojo.PurchaseProviderSummary;
import com.kgc.cgapi.pojo.PurchaseStaffSummary;
import com.kgc.cgprovider.dao.PurchaseProviderSummaryMapper;
import com.kgc.cgprovider.service.PurchaseProviderSummaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class PurchaseProviderSummaryServiceImpl implements PurchaseProviderSummaryService {

    private Logger logger = LoggerFactory.getLogger(PurchaseProviderSummaryServiceImpl.class);

    @Autowired
    private PurchaseProviderSummaryMapper purchaseProviderSummaryMapper;

    @Override
    public ResponseMsg selectSummaryByPurchaseProvider(Map<String, Object> map) {
        logger.info("PurchaseProviderSummaryServiceImpl selectSummaryByPurchaseProvider map:{}", map);
        ResponseMsg responseMsg = new ResponseMsg();
        PageInfo<PurchaseProviderSummary> pageInfo = new PageInfo<>();
        pageInfo.setPageNo(map.get("pageNo") == null ? 1 : Integer.parseInt(map.get("pageNo").toString()));
        pageInfo.setPageSize(map.get("pageSize") == null ? 10 : Integer.parseInt(map.get("pageSize").toString()));
        Page page = PageHelper.startPage(pageInfo.getPageNo(), pageInfo.getPageSize());
        List<PurchaseProviderSummary> purchaseProviderSummaryList = purchaseProviderSummaryMapper.selectSummaryByPurchaseProvider(map);
        pageInfo.setList(purchaseProviderSummaryList);
        pageInfo.setTotal((int) page.getTotal());
        responseMsg.setData(pageInfo);
        return responseMsg;
    }

    @Override
    public ResponseMsg selectSummaryByStaff(Map<String, Object> map) {
        logger.info("PurchaseProviderSummaryServiceImpl selectSummaryByStaff map:{}", map);
        ResponseMsg responseMsg = new ResponseMsg();
        PageInfo<PurchaseStaffSummary> pageInfo = new PageInfo<>();
        pageInfo.setPageNo(map.get("pageNo") == null ? 1 : Integer.parseInt(map.get("pageNo").toString()));
        pageInfo.setPageSize(map.get("pageSize") == null ? 10 : Integer.parseInt(map.get("pageSize").toString()));
        Page page = PageHelper.startPage(pageInfo.getPageNo(), pageInfo.getPageSize());
        List<PurchaseStaffSummary> purchaseStaffSummaryList = purchaseProviderSummaryMapper.selectSummaryByStaff(map);
        pageInfo.setList(purchaseStaffSummaryList);
        pageInfo.setTotal((int) page.getTotal());
        responseMsg.setData(pageInfo);
        return responseMsg;
    }

    @Override
    public ResponseMsg getPurchaseOrderDataByDate() {
        logger.info("PurchaseProviderSummaryServiceImpl getPurchaseOrderDataByDate is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> purchaseOrderDataByDateMap = purchaseProviderSummaryMapper.getPurchaseOrderDataByDate();
        if (purchaseOrderDataByDateMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(purchaseOrderDataByDateMap);
        return msg;
    }

    @Override
    public ResponseMsg getPurchaseInBoundDataByTime() {
        logger.info("PurchaseProviderSummaryServiceImpl getPurchaseInBoundDataByTime is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> purchaseInBoundDataByTimeMap = purchaseProviderSummaryMapper.getPurchaseInBoundDataByTime();
        if (purchaseInBoundDataByTimeMap == null || purchaseInBoundDataByTimeMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(purchaseInBoundDataByTimeMap);
        return msg;
    }

    @Override
    public ResponseMsg getPurchaseRequestDataByTime() {
        logger.info("PurchaseProviderSummaryServiceImpl getPurchaseRequestDataByTime is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> purchaseRequestDataByTimeMap = purchaseProviderSummaryMapper.getPurchaseRequestDataByTime();
        if (purchaseRequestDataByTimeMap == null || purchaseRequestDataByTimeMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(purchaseRequestDataByTimeMap);
        return msg;
    }

    @Override
    public ResponseMsg getPurchaseReturnDataByTime() {
        logger.info("PurchaseProviderSummaryServiceImpl getPurchaseReturnDataByTime is start...");
        ResponseMsg msg = new ResponseMsg();
        Map<String, Object> purchaseReturnDataByTimeMap = purchaseProviderSummaryMapper.getPurchaseReturnDataByTime();
        if (purchaseReturnDataByTimeMap == null || purchaseReturnDataByTimeMap.isEmpty()) {
            msg.setCode("301");
            msg.setMsg("未查询到相关信息");
            return msg;
        }
        msg.setCode("200");
        msg.setData(purchaseReturnDataByTimeMap);
        return msg;
    }
}
